package Person;
use Moose;

has 'ssn' => (
	is	  => 'ro',
	isa	  => 'Str',
	predicate => 'has_ssn',
);

has 'country_of_residence' => (
	is	  => 'ro',
	isa 	  => 'Str',
	default   => 'usa'
);

has 'first_name' => (
	is  => 'ro',
	isa => 'Str',
);

has 'last_name' => (
	is  => 'ro',
	isa => 'Str',
);

around BUILDARGS => sub {
	my $orig  = shift;
	my $class = shift;
	
	if ( @_ == 1 && ! ref $_[0] ) {
		return $class->$orig(ssn => $_[0]);
	}
	else {
		return $class->$orig(@_);
	}
};

sub BUILD {
	my $self = shift;
	
	if ( $self->country_of_residence eq 'usa' ) {
		die 'Cannot create a Person who lives in the USA without an ssn.'
			unless $self->has_ssn;
	}
}

__PACKAGE__->meta->make_immutable;

my $person = Person->new('123-45-6789');

print $person->country_of_residence;